Skip to content

Refactor strings.NewReader into bytes to avoid allocations #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2025

Conversation

javuto
Copy link
Collaborator

@javuto javuto commented Jun 1, 2025

Avoid using strings.NewReader when bytes.NewReader can be used and avoid unnecessary allocation.

@javuto javuto requested a review from Copilot June 1, 2025 19:29
@javuto javuto added refactor Refactorization of code ⚡️ performance Performance related issues labels Jun 1, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the code to use bytes.NewReader instead of strings.NewReader, thereby reducing unnecessary allocations. It also standardizes error message formatting in the database module.

  • Replace string-based readers with byte-based readers
  • Update error message capitalization for consistency

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/logging/splunk.go Changed from strings.NewReader(string(jsonEvents)) to bytes.NewReader(jsonEvents)
pkg/logging/logstash.go Replaced strings.NewReader(string(data)) with bytes.NewReader(data)
pkg/logging/graylog.go Updated strings.NewReader to bytes.NewReader for JSON messages
pkg/logging/elastic.go Refactored error index request body to use bytes.NewReader(jsonEvent)
pkg/logging/db.go Adjusted error message capitalization for consistent logging

@javuto javuto merged commit 8433d1a into main Jun 1, 2025
54 checks passed
@javuto javuto deleted the bytes-newreader-refactor branch June 1, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡️ performance Performance related issues refactor Refactorization of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant